<?php 
	session_start();
	require_once($_SERVER['DOCUMENT_ROOT']."/includes/sugar.php");
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/Account.class.php");
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/HumeurDatabase.class.php");
	if(empty($_GET['pass']) || empty($_GET['id'])){
		echo "Erreur : Aucun mot de passe ou aucun identifiant rentr&eacute;.";
	}
	else
	{
		$db = new HumeurDatabase();
		if(mysql_num_rows($db->query("SELECT * FROM accounts WHERE mail = '".rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($_GET['pass']), base64_decode($_GET['id']), MCRYPT_MODE_CBC, md5(md5($_GET['pass']))), "\0")."';")) == 0){
			echo "Erreur : Identifiant ou mot de passe &eacute;ronn&eacute;.";
		}
		else
		{
			$allAccounts = $db->query("SELECT mail FROM accounts");
			$jsonResult = array();
			while($jsonAccount = mysql_fetch_assoc($allAccounts)){
				$jsonResult[] = new Account($jsonAccount['mail']);
			}
			echo json_encode($jsonResult);
		}		
	}

?>